#include "stdafx.h"

int ElectricDevice::currPower = 0;
int ElectricDevice::systemPower = 20;

ElectricDevice::ElectricDevice(const char* category, double power)
{
	if(power < 0)
	{
		throw WrongParameterExeption("");
	}
	this->category = new char[strlen(category) +1];
	strcpy_s(this->category,(strlen(category)+1),category);
	this->power = power;
}

ElectricDevice::ElectricDevice(const ElectricDevice& e)
{
	this->category = new char[strlen(e.category) +1];
	strcpy_s(this->category,(strlen(e.category)+1),e.category);
	this->power = e.power;
}

ElectricDevice& ElectricDevice::operator = (const ElectricDevice& e)
{
	if(strcmp(this->category,category) && this->power == e.power)
	{
		return *this;
	}
	else
	{
		this->category = new char[strlen(e.category) + 1];
		strcpy_s(this->category,(strlen(e.category)+1),e.category);
		this->power = power;
		return *this;
	}
}

ElectricDevice::~ElectricDevice()
{
	delete [] category;
}

void ElectricDevice::connectDevice()
{
	this->connected = true;
}

bool ElectricDevice::isEnoughLoad(ElectricDevice& e)
{
	if(currPower + e.power <= systemPower)
	{
		return true;
	}
	else
	{
		return false;
	}
}